import { postStream } from '@/api/Http'

export interface NameAnalysisParams {
  name: string
  gender: string
  birthYear?: number
}

export class NameAnalysisApi {
  static async analyzeName(params: NameAnalysisParams): Promise<ReadableStreamDefaultReader<Uint8Array>> {
    const response = await postStream('/entertainment/nameAnalysis/analyze', params)

    if (!response.ok) {
      throw new Error(`Analysis failed: ${response.statusText}`)
    }

    if (!response.body) {
      throw new Error('No response body')
    }

    return response.body.getReader()
  }
}